package cn.le.thread;

import java.util.concurrent.TimeUnit;

/**
 * Created by admin on 2017/7/21.
 */
public class InnerRunnable {

    private int countDown = 5;
    private Thread t;
    public InnerRunnable(String name)
    {
        t = new Thread(new Runnable() {
            @Override
            public void run() {

                try
                {
                    while (true)
                    {
                        System.out.println(this);
                        if(--countDown == 0)
                        {
                            return;
                        }
                        TimeUnit.MILLISECONDS.sleep(10);
                    }
                }catch (InterruptedException e)
                {
                    e.printStackTrace();
                }
            }
            public String toString()
            {
                return Thread.currentThread().getName()+": "+countDown;
            }

        },name);
    }

}
